import 'package:flutter/material.dart';
import 'package:sports_new/utils/utils.dart';

import '../../../resources/colours.dart';
import '../../../widgets/date_tab_bar.dart';

class RectDateBar extends StatelessWidget {
  const RectDateBar({super.key, required this.dateList, required this.controller, this.margin, required this.backColor, required this.tabColor, required this.labelColor, this.border, this.labelAbove, this.showAbove});
  const RectDateBar.dark(
      {super.key, required this.dateList,
      required this.controller,
      this.margin, this.border, this.labelAbove, this.showAbove}):
      backColor = const ColorSet(gradient: [Color(0xFF092546),Color(0xFF071226)]),
      tabColor = const ColorSet(gradient: [Color(0xFFF6FDFF),Color(0xFFB1ECFF)]),
      labelColor = const Color(0xFF030C1A);
  RectDateBar.light(
      {super.key, required this.dateList,
        required this.controller,
        this.margin, this.labelAbove, this.showAbove}):
        backColor = const ColorSet(color: Colors.white),
        tabColor = const ColorSet(gradient: [Color(0xFFF54D4F),Color(0xFFF53C6A)]),
        labelColor = Colours.white,
        border = Border.all(color: Colours.main.withOpacity(0.2),width: 1);

  final List<DateTime> dateList;
  final TabController controller;
  final EdgeInsets? margin;
  final ColorSet backColor;
  final ColorSet tabColor;
  final Color labelColor;
  final Border? border;
  final Widget? labelAbove;
  final List<int>? showAbove;

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 66,
      clipBehavior: Clip.antiAlias,
      margin: margin ?? const EdgeInsets.fromLTRB(8, 12, 8, 0),
      decoration: BoxDecoration(
        color: backColor.color,
        gradient: backColor.gradient.hasValue?LinearGradient(
          colors: backColor.gradient!,
          begin: Alignment.topCenter,
          end: Alignment.bottomCenter
        ):null,
        borderRadius: BorderRadius.circular(7),
        border: border
      ),
      child: DateTabBar(
          indicator: BoxDecoration(
            borderRadius: BorderRadius.circular(7),
              color: tabColor.color,
              gradient: tabColor.gradient.hasValue?LinearGradient(
                  colors: tabColor.gradient!,
                  begin: Alignment.topCenter,
                  end: Alignment.bottomCenter):null),
          controller: controller,
          dateList: dateList,
          labelColor: labelColor,
          isScrollable: false,
          indicatorSize: TabBarIndicatorSize.tab,
          dataFormat: 'dd',
          textSpacing: 8,
          labelAbove: labelAbove,
          showAbove: showAbove,
          subTextStyle: const TextStyle(
              fontSize: 14,fontWeight: FontWeight.w500),
          labelInnerPadding: const EdgeInsets.symmetric(vertical: 5),
          indicatorPadding: const EdgeInsets.all(1),
          labelPadding: const EdgeInsets.all(1),
      ),
    );
  }
}

class ColorSet{
  final Color? color;
  final List<Color>? gradient;

  const ColorSet({this.color, this.gradient});
}